﻿@inherits BaseItemComponent

<CascadingValue Value="this" IsFixed="true">
    @ChildContent
</CascadingValue>

@code {
    private IDictionary<string, object> label = new Dictionary<string, object>();
    private IDictionary<string, object> itemStyle = new Dictionary<string, object>();
    private Dictionary<string, object> emphasis = new Dictionary<string, object>();
    private Dictionary<string, object> blur = new Dictionary<string, object>();
    private Dictionary<string, object> select = new Dictionary<string, object>();

    /// <summary>
    /// 类目名称
    /// </summary>
    [Parameter]
    public string? name { get; set; }

    /// <summary>
    /// 该类目节点标记的图形。包括 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow', 'none'
    /// </summary>
    [Parameter]
    public string? symbol { get; set; }

    /// <summary>
    /// 该类目节点标记的大小
    /// </summary>
    [Parameter]
    public dynamic? symbolSize { get; set; }

    /// <summary>
    /// 该类目节点标记的旋转角度（而非弧度）
    /// </summary>
    [Parameter]
    public string? symbolRotate { get; set; }

    /// <summary>
    /// 是否在缩放时保持该图形的长宽比
    /// </summary>
    [Parameter]
    public bool? symbolKeepAspect { get; set; }

    /// <summary>
    /// 该类目节点标记相对于原本位置的偏移
    /// </summary>
    [Parameter]
    public object[]? symbolOffset { get; set; }

    protected override IDictionary<string, object> LoadSetting()
    {
        IDictionary<string, object>? setting = null;

        if (Base is Series scomponent)
        {
            scomponent.SetCategories((categories) =>
            {
                setting = categories;
            });
        }

        return setting ?? new Dictionary<string, object>();
    }

    public override void SetSetting(IDictionary<string, object> setting)
    {
        if (!string.IsNullOrEmpty(name))
            FillSetting("name", name);

        if (!string.IsNullOrEmpty(symbol))
            FillSetting("symbol", symbol);

        if (symbolSize != null)
            FillSetting("symbolSize", symbolSize);

        if (!string.IsNullOrEmpty(symbolRotate))
            FillSetting("symbolRotate", symbolRotate);

        if (symbolKeepAspect.HasValue)
            FillSetting("symbolKeepAspect", symbolKeepAspect);

        if (symbolOffset != null && symbolOffset.Length > 0)
            FillSetting("symbolOffset", symbolOffset);
    }

    public void SetLabel(Action<IDictionary<string, object>> action)
    {
        FillSetting("label", label);
        action?.Invoke(label);
    }

    public void SetItemStyle(Action<IDictionary<string, object>> action)
    {
        FillSetting("itemStyle", itemStyle);
        action?.Invoke(itemStyle);
    }

    public void SetEmphasis(Action<IDictionary<string, object>> action)
    {
        FillSetting("emphasis", emphasis);
        action?.Invoke(emphasis);
    }

    public void SetBlur(Action<IDictionary<string, object>> action)
    {
        FillSetting("blur", blur);
        action?.Invoke(blur);
    }

    public void SetSelect(Action<IDictionary<string, object>> action)
    {
        FillSetting("select", select);
        action?.Invoke(select);
    }
}
